<?php

namespace App\Admin\Controllers;

use App\Models\Stage;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class StageController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('道具管理');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('编辑道具');

            $content->body($this->form()->edit($id));
        });
    }


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Stage::class, function (Grid $grid) {

            //$grid->model()->withoutGlobalScopes()->orderBy('noOpen');
            $grid->StageID('ID')->sortable();
            $grid->StageImg('图标')->image('',50,50);
            $grid->StageName('名称');
            $grid->StagePrice('价格');
            $grid->StageIntr('描述');
            //$grid->shortDesc('缩略显示');
            //$grid->noOpen('状态')->switch([
            //    'on'  => ['value' => 0, 'text' => '可用', 'color' => 'primary'],
            //    'off' => ['value' => 1, 'text' => '禁用', 'color' => 'default'],
            //]);
            $grid->disableCreateButton();
            $grid->disablePagination();
            $grid->disableFilter();
            $grid->disableExport();
            $grid->disableRowSelector();
            $grid->actions(function($actions) {
                $actions->disableDelete();
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Stage::class, function (Form $form) {
            //$form->model()->withoutGlobalScopes();
            $form->display('StageID', 'ID');
            
            $form->text('StageName','名称')->rules('required');
            $form->image('StageImg','图标')->rules('required');
            $form->number('StagePrice','价格')->rules('required');
            $form->text('StageIntr','描述');
            //$form->text('shortDesc','缩略显示');
            //$form->switch('noOpen','状态')->states([
            //    'on'  => ['value' => 0, 'text' => '可用', 'color' => 'primary'],
            //    'off' => ['value' => 1, 'text' => '禁用', 'color' => 'default'],
            //]);
        });
    }
}
